<template>
  <common-list>
    <!-- 头部搜素start -->
    <common-search slot="search" @search="handleQuery" @reset="resetQuery">
      <el-form
        @submit.native.prevent
        :model="query"
        ref="queryForm"
        :inline="true"
        label-width="65px"
      >
        <el-form-item label="账号" prop="account">
          <common-input
            v-model="query.account"
            clearable
            :verify="false"
            @enter="handleQuery"
          />
        </el-form-item>

        <el-form-item label="访问时间">
          <el-date-picker
            v-model="date"
            type="datetimerange"
            @change="dateChange"
            value-format="yyyy-MM-dd HH:mm:ss"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            :default-time="['00:00:00', '23:59:59']"
          >
          </el-date-picker>
          <!-- <el-date-picker
            v-model="query.daterange"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
          ></el-date-picker> -->
        </el-form-item>
      </el-form>
    </common-search>
    <!-- 头部搜素end -->
    <!--列表 start-->
    <common-table slot="content" v-loading="loading" :data="list">
      <el-table-column label="账号" prop="account" align="left" />

      <el-table-column
        label="访问次数"
        align="left"
        prop="totalVisit"
      ></el-table-column>
      <el-table-column
        label="异常访问次数"
        align="left"
        prop="errorVisit"
      ></el-table-column>

      <el-table-column
        label="最新访问时间"
        align="left"
        prop="lastTime"
        show-overflow-tooltip
      ></el-table-column>

      <el-table-column label="操作" align="left" width="52">
        <template slot-scope="{ row }">
          <el-button
            type="text"
            @click="detail(row)"
            v-hasPermi="['apisecurity:accountaudit:detail']"
            >画像</el-button
          >
        </template>
      </el-table-column>
    </common-table>
    <pagination
      slot="pagination"
      v-show="total > 0"
      :total="total"
      :page.sync="query.pageNum"
      :limit.sync="query.pageSize"
      @pagination="getList"
    />

    <template v-if="showDetail">
      <detail ref="detail" @close="showDetail = false" />
    </template>
  </common-list>
</template>

<script>
import Detail from "./components/detail";
import BaseList from "@/mixins/BaseList";
import { selectList } from "@/api/apisecurity/portrait/index";
export default {
  mixins: [BaseList],
  components: { Detail },
  props: {},
  data() {
    return {
      filterMenu: "", //菜单筛选
      showSearch: true, // 查询部分显示
      total: 0, // 总条数
      loading: false, // table 加载中
      list: [], // 数据列
      query: {
        pageNum: 1,
        pageSize: 10,
        account: null,
        beginTime: null,
        endTime: null,
      }, // 查询条件
      businessTypeList: [],
      currentParent: 1,
      singleDeptList: [],
      showDetail: false,
      date: [],
    };
  },
  watch: {},
  computed: {},
  methods: {
    dateChange() {
      let endTime = null,
        beginTime = null;
      if (this.date && this.date.length > 0) {
        beginTime = this.date[0];
        endTime = this.date[1];
      }
      this.query.beginTime = beginTime;
      this.query.endTime = endTime;
    },
    /**
     * 获取列表
     */
    getList() {
      this.loading = true;
      selectList(this.query)
        .then((res) => {
          if (res && res.code === 200) {
            this.list = res.rows;
            this.total = res.total;
          } else {
            this.list = [];
            this.total = 0;
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },
    /**
     * 查询
     */
    handleQuery() {
      this.query.pageNum = 1;
      this.getList();
    },
    /**
     * 重置查询
     */
    resetQuery() {
      this.query = this.$options.data().query;
      this.date = [];
    },
    /**
     * 详情
     */
    detail(row) {
      this.showDetail = true;
      this.$nextTick(() => {
        this.$refs.detail.show(
          row
            ? {
                account: row.account,
                beginTime:
                  this.date && this.date.length > 0 ? this.date[0] : null,
                endTime:
                  this.date && this.date.length > 0 ? this.date[1] : null,
              }
            : {}
        );
      });
    },
  },
  created() {
    this.getList();
  },
  mounted() {},
};
</script>
